<!DOCTYPE html>
<html lang="zh-CN" data-theme="light">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>基于STM32的智能宠物小屋设计</title>
    <script src="https://cdn.tailwindcss.com"></script>
    <link href="https://cdn.bootcdn.net/ajax/libs/daisyui/4.12.10/full.min.css" rel="stylesheet">
    <link href="https://cdn.bootcdn.net/ajax/libs/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <style>
        .gradient-bg {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        }
        .glass-card {
            background: rgba(255, 255, 255, 0.1);
            backdrop-filter: blur(10px);
            border: 1px solid rgba(255, 255, 255, 0.2);
        }
        .code-block {
            background: #1e293b;
            color: #e2e8f0;
            font-family: 'Consolas', 'Monaco', monospace;
        }
        .sensor-card {
            transition: transform 0.3s ease, box-shadow 0.3s ease;
        }
        .sensor-card:hover {
            transform: translateY(-5px);
            box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
        }
    </style>
</head>
<body class="bg-gray-50">
    <!-- Hero Section -->
    <div class="gradient-bg text-white py-20">
        <div class="container mx-auto px-6">
            <div class="text-center">
                <h1 class="text-5xl font-bold mb-4">基于STM32的智能宠物小屋设计</h1>
                <p class="text-xl opacity-90">现代智能家居与宠物护理的完美结合</p>
                <div class="mt-8 flex justify-center space-x-4">
                    <span class="glass-card px-4 py-2 rounded-full text-sm">
                        <i class="fas fa-microchip mr-2"></i>STM32F103C8T6
                    </span>
                    <span class="glass-card px-4 py-2 rounded-full text-sm">
                        <i class="fas fa-wifi mr-2"></i>ESP8266 WiFi
                    </span>
                    <span class="glass-card px-4 py-2 rounded-full text-sm">
                        <i class="fas fa-mobile-alt mr-2"></i>手机APP控制
                    </span>
                </div>
            </div>
        </div>
    </div>

    <!-- System Overview -->
    <div class="container mx-auto px-6 py-16">
        <div class="text-center mb-12">
            <h2 class="text-3xl font-bold text-gray-800 mb-4">系统总体架构</h2>
            <p class="text-gray-600">五层架构设计，实现智能化宠物护理</p>
        </div>

        <div class="grid md:grid-cols-5 gap-6">
            <div class="sensor-card bg-white p-6 rounded-xl shadow-lg">
                <div class="text-center">
                    <div class="w-16 h-16 bg-blue-100 rounded-full flex items-center justify-center mx-auto mb-4">
                        <i class="fas fa-eye text-2xl text-blue-600"></i>
                    </div>
                    <h3 class="font-bold text-lg mb-2">感知层</h3>
                    <p class="text-sm text-gray-600">温湿度、重量、水位传感器</p>
                </div>
            </div>

            <div class="sensor-card bg-white p-6 rounded-xl shadow-lg">
                <div class="text-center">
                    <div class="w-16 h-16 bg-green-100 rounded-full flex items-center justify-center mx-auto mb-4">
                        <i class="fas fa-brain text-2xl text-green-600"></i>
                    </div>
                    <h3 class="font-bold text-lg mb-2">控制层</h3>
                    <p class="text-sm text-gray-600">STM32核心处理器</p>
                </div>
            </div>

            <div class="sensor-card bg-white p-6 rounded-xl shadow-lg">
                <div class="text-center">
                    <div class="w-16 h-16 bg-red-100 rounded-full flex items-center justify-center mx-auto mb-4">
                        <i class="fas fa-cogs text-2xl text-red-600"></i>
                    </div>
                    <h3 class="font-bold text-lg mb-2">执行层</h3>
                    <p class="text-sm text-gray-600">风扇、舵机、水泵</p>
                </div>
            </div>

            <div class="sensor-card bg-white p-6 rounded-xl shadow-lg">
                <div class="text-center">
                    <div class="w-16 h-16 bg-purple-100 rounded-full flex items-center justify-center mx-auto mb-4">
                        <i class="fas fa-desktop text-2xl text-purple-600"></i>
                    </div>
                    <h3 class="font-bold text-lg mb-2">交互层</h3>
                    <p class="text-sm text-gray-600">OLED显示 + 按键</p>
                </div>
            </div>

            <div class="sensor-card bg-white p-6 rounded-xl shadow-lg">
                <div class="text-center">
                    <div class="w-16 h-16 bg-yellow-100 rounded-full flex items-center justify-center mx-auto mb-4">
                        <i class="fas fa-cloud text-2xl text-yellow-600"></i>
                    </div>
                    <h3 class="font-bold text-lg mb-2">通信层</h3>
                    <p class="text-sm text-gray-600">Wi-Fi + 手机APP</p>
                </div>
            </div>
        </div>
    </div>

    <!-- Hardware Design -->
    <div class="bg-gray-100 py-16">
        <div class="container mx-auto px-6">
            <h2 class="text-3xl font-bold text-center text-gray-800 mb-12">硬件设计与实现</h2>

            <div class="grid lg:grid-cols-2 gap-8">
                <!-- Main Controller -->
                <div class="bg-white p-6 rounded-xl shadow-lg">
                    <h3 class="text-xl font-bold mb-4 flex items-center">
                        <i class="fas fa-microchip text-blue-600 mr-2"></i>
                        主控模块
                    </h3>
                    <div class="space-y-3">
                        <div class="flex justify-between">
                            <span class="font-medium">核心芯片:</span>
                            <span class="text-gray-600">STM32F103C8T6</span>
                        </div>
                        <div class="flex justify-between">
                            <span class="font-medium">特点:</span>
                            <span class="text-gray-600">资源丰富、性价比高</span>
                        </div>
                        <div class="flex justify-between">
                            <span class="font-medium">接口:</span>
                            <span class="text-gray-600">PWM、ADC、I2C、UART、GPIO</span>
                        </div>
                    </div>
                </div>

                <!-- Sensors -->
                <div class="bg-white p-6 rounded-xl shadow-lg">
                    <h3 class="text-xl font-bold mb-4 flex items-center">
                        <i class="fas fa-thermometer-half text-red-600 mr-2"></i>
                        传感器模块
                    </h3>
                    <div class="space-y-4">
                        <div class="border-l-4 border-blue-500 pl-4">
                            <h4 class="font-bold">DHT11温湿度传感器</h4>
                            <p class="text-sm text-gray-600">数字单总线协议，GPIO连接</p>
                        </div>
                        <div class="border-l-4 border-green-500 pl-4">
                            <h4 class="font-bold">HX711 + 称重传感器</h4>
                            <p class="text-sm text-gray-600">24位高精度A/D转换，粮仓重量检测</p>
                        </div>
                        <div class="border-l-4 border-yellow-500 pl-4">
                            <h4 class="font-bold">水位传感器</h4>
                            <p class="text-sm text-gray-600">模拟输出，ADC接口读取</p>
                        </div>
                    </div>
                </div>

                <!-- Actuators -->
                <div class="bg-white p-6 rounded-xl shadow-lg">
                    <h3 class="text-xl font-bold mb-4 flex items-center">
                        <i class="fas fa-cogs text-purple-600 mr-2"></i>
                        执行模块
                    </h3>
                    <div class="space-y-4">
                        <div class="flex items-center space-x-3">
                            <div class="w-3 h-3 bg-blue-500 rounded-full"></div>
                            <span>SG90舵机 - 投食控制</span>
                        </div>
                        <div class="flex items-center space-x-3">
                            <div class="w-3 h-3 bg-green-500 rounded-full"></div>
                            <span>5V直流风扇 - 温度调节</span>
                        </div>
                        <div class="flex items-center space-x-3">
                            <div class="w-3 h-3 bg-red-500 rounded-full"></div>
                            <span>小型水泵 - 自动补水</span>
                        </div>
                    </div>
                </div>

                <!-- Communication -->
                <div class="bg-white p-6 rounded-xl shadow-lg">
                    <h3 class="text-xl font-bold mb-4 flex items-center">
                        <i class="fas fa-wifi text-green-600 mr-2"></i>
                        通信模块
                    </h3>
                    <div class="space-y-3">
                        <div class="flex justify-between">
                            <span class="font-medium">模块:</span>
                            <span class="text-gray-600">ESP-01S ESP8266</span>
                        </div>
                        <div class="flex justify-between">
                            <span class="font-medium">连接:</span>
                            <span class="text-gray-600">UART接口</span>
                        </div>
                        <div class="flex justify-between">
                            <span class="font-medium">协议:</span>
                            <span class="text-gray-600">AT指令 + MQTT</span>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <!-- Software Design -->
    <div class="container mx-auto px-6 py-16">
        <h2 class="text-3xl font-bold text-center text-gray-800 mb-12">软件设计与实现</h2>

        <!-- Development Environment -->
        <div class="bg-white p-8 rounded-xl shadow-lg mb-8">
            <h3 class="text-2xl font-bold mb-6 flex items-center">
                <i class="fas fa-tools text-blue-600 mr-2"></i>
                开发环境
            </h3>
            <div class="grid md:grid-cols-3 gap-6">
                <div class="text-center p-4 bg-gray-50 rounded-lg">
                    <i class="fas fa-code text-3xl text-blue-600 mb-2"></i>
                    <h4 class="font-bold">IDE</h4>
                    <p class="text-gray-600">Keil uVision 5</p>
                </div>
                <div class="text-center p-4 bg-gray-50 rounded-lg">
                    <i class="fas fa-cube text-3xl text-green-600 mb-2"></i>
                    <h4 class="font-bold">配置工具</h4>
                    <p class="text-gray-600">STM32CubeMX</p>
                </div>
                <div class="text-center p-4 bg-gray-50 rounded-lg">
                    <i class="fas fa-book text-3xl text-purple-600 mb-2"></i>
                    <h4 class="font-bold">库文件</h4>
                    <p class="text-gray-600">HAL库 + 外设驱动</p>
                </div>
            </div>
        </div>

        <!-- Core Code -->
        <div class="bg-white p-8 rounded-xl shadow-lg">
            <h3 class="text-2xl font-bold mb-6 flex items-center">
                <i class="fas fa-code text-green-600 mr-2"></i>
                核心代码逻辑
            </h3>
            <div class="code-block p-6 rounded-lg overflow-x-auto">
                <pre><code>// 定义全局变量与阈值
float temp_threshold_high = 30.0;
int food_weight_threshold = 100;  // 单位: 克
int water_level_threshold = 200;  // ADC值, 需实验测定

void main() {
    // 初始化HX711, 并去皮(清零)
    HX711_Tare();
    
    // 初始化...
    while(1) {
        // 1. 读取传感器
        temperature = DHT11_GetTemperature();
        current_food_weight = HX711_GetWeight();
        water_level = ADC_Read(WATER_SENSOR_CH);
        
        // 2. OLED显示
        OLED_ShowString(0, 0, "Temp:");
        OLED_ShowNumber(60, 0, temperature);
        OLED_ShowString(0, 2, "Food:");
        OLED_ShowNumber(60, 2, current_food_weight);
        OLED_ShowString(0, 4, "Water:");
        OLED_ShowNumber(60, 4, water_level);
        
        // 3. 自动控制逻辑
        // 3.1 温度控制
        if (temperature > temp_threshold_high) {
            FAN_ON();
        } else {
            FAN_OFF();
        }
        
        // 3.2 投食控制
        if (current_food_weight < food_weight_threshold) {
            Servo_Feed(180);  // 舵机旋转180度, 投食一次
            HAL_Delay(1000);
            Servo_Feed(0);    // 舵机归位, 关闭食口
        }
        
        // 3.3 补水控制
        if (water_level < water_level_threshold) {
            PUMP_ON();
        } else {
            PUMP_OFF();
        }
        
        // 4. 处理通信
        if (time_to_send_data()) {
            sprintf(json_data, "{\"temp\":%.1f,\"food\":%d,\"water\":%d}", 
                    temperature, current_food_weight, water_level);
            ESP8266_SendToCloud(json_data);
        }
        
        HAL_Delay(5000);  // 每5秒检测一次
    }
}</code></pre>
            </div>
        </div>
    </div>

    <!-- System Testing -->
    <div class="bg-gray-100 py-16">
        <div class="container mx-auto px-6">
            <h2 class="text-3xl font-bold text-center text-gray-800 mb-12">系统测试与优化</h2>

            <div class="grid lg:grid-cols-2 gap-8">
                <!-- Functional Testing -->
                <div class="bg-white p-6 rounded-xl shadow-lg">
                    <h3 class="text-xl font-bold mb-4 flex items-center">
                        <i class="fas fa-vial text-blue-600 mr-2"></i>
                        功能测试
                    </h3>
                    <div class="space-y-4">
                        <div class="flex items-start space-x-3">
                            <div class="w-2 h-2 bg-red-500 rounded-full mt-2"></div>
                            <div>
                                <h4 class="font-bold">温控测试</h4>
                                <p class="text-sm text-gray-600">加热DHT11，观察风扇启动</p>
                            </div>
                        </div>
                        <div class="flex items-start space-x-3">
                            <div class="w-2 h-2 bg-green-500 rounded-full mt-2"></div>
                            <div>
                                <h4 class="font-bold">投食测试</h4>
                                <p class="text-sm text-gray-600">减少粮食重量，观察舵机动作</p>
                            </div>
                        </div>
                        <div class="flex items-start space-x-3">
                            <div class="w-2 h-2 bg-blue-500 rounded-full mt-2"></div>
                            <div>
                                <h4 class="font-bold">补水测试</h4>
                                <p class="text-sm text-gray-600">模拟缺水，观察水泵启动</p>
                            </div>
                        </div>
                        <div class="flex items-start space-x-3">
                            <div class="w-2 h-2 bg-purple-500 rounded-full mt-2"></div>
                            <div>
                                <h4 class="font-bold">远程测试</h4>
                                <p class="text-sm text-gray-600">APP控制，验证响应</p>
                            </div>
                        </div>
                    </div>
                </div>

                <!-- Reliability Testing -->
                <div class="bg-white p-6 rounded-xl shadow-lg">
                    <h3 class="text-xl font-bold mb-4 flex items-center">
                        <i class="fas fa-shield-alt text-green-600 mr-2"></i>
                        可靠性测试
                    </h3>
                    <div class="space-y-4">
                        <div class="bg-yellow-50 p-4 rounded-lg">
                            <h4 class="font-bold text-yellow-800">防误触发测试</h4>
                            <p class="text-sm text-yellow-700">模拟宠物触碰，检查稳定性</p>
                        </div>
                        <div class="bg-blue-50 p-4 rounded-lg">
                            <h4 class="font-bold text-blue-800">长时间运行测试</h4>
                            <p class="text-sm text-blue-700">24小时连续运行，检查稳定性</p>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <!-- Future Prospects -->
    <div class="container mx-auto px-6 py-16">
        <div class="text-center mb-12">
            <h2 class="text-3xl font-bold text-gray-800 mb-4">未来展望</h2>
            <p class="text-gray-600">智能宠物小屋的无限可能</p>
        </div>

        <div class="grid md:grid-cols-2 lg:grid-cols-4 gap-6">
            <div class="bg-white p-6 rounded-xl shadow-lg text-center">
                <div class="w-16 h-16 bg-red-100 rounded-full flex items-center justify-center mx-auto mb-4">
                    <i class="fas fa-video text-2xl text-red-600"></i>
                </div>
                <h3 class="font-bold mb-2">视频监控</h3>
                <p class="text-sm text-gray-600">ESP32-CAM实时画面</p>
            </div>

            <div class="bg-white p-6 rounded-xl shadow-lg text-center">
                <div class="w-16 h-16 bg-blue-100 rounded-full flex items-center justify-center mx-auto mb-4">
                    <i class="fas fa-robot text-2xl text-blue-600"></i>
                </div>
                <h3 class="font-bold mb-2">AI智能识别</h3>
                <p class="text-sm text-gray-600">宠物身份与行为分析</p>
            </div>

            <div class="bg-white p-6 rounded-xl shadow-lg text-center">
                <div class="w-16 h-16 bg-green-100 rounded-full flex items-center justify-center mx-auto mb-4">
                    <i class="fas fa-microphone text-2xl text-green-600"></i>
                </div>
                <h3 class="font-bold mb-2">语音交互</h3>
                <p class="text-sm text-gray-600">远程语音安抚宠物</p>
            </div>

            <div class="bg-white p-6 rounded-xl shadow-lg text-center">
                <div class="w-16 h-16 bg-yellow-100 rounded-full flex items-center justify-center mx-auto mb-4">
                    <i class="fas fa-solar-panel text-2xl text-yellow-600"></i>
                </div>
                <h3 class="font-bold mb-2">太阳能供电</h3>
                <p class="text-sm text-gray-600">绿色能源自给自足</p>
            </div>
        </div>
    </div>

    <!-- Footer -->
    <footer class="bg-gray-800 text-white py-8">
        <div class="container mx-auto px-6 text-center">
            <p class="mb-4">基于STM32的智能宠物小屋设计</p>
            <p class="text-gray-400">
                本文来源：<a href="https://yifeng.blog.csdn.net/article/details/151367041" class="text-blue-400 hover:underline" target="_blank">CSDN博客 - 基于STM32的智能宠物小屋设计</a>
            </p>
        </div>
    </footer>

    <script>
        // 动态效果
        document.addEventListener('DOMContentLoaded', function() {
            const cards = document.querySelectorAll('.sensor-card');
            cards.forEach((card, index) => {
                setTimeout(() => {
                    card.style.opacity = '0';
                    card.style.transform = 'translateY(20px)';
                    card.style.transition = 'all 0.6s ease';
                    setTimeout(() => {
                        card.style.opacity = '1';
                        card.style.transform = 'translateY(0)';
                    }, 100);
                }, index * 200);
            });
        });
    </script>
</body>
</html>